package ar.unq.edu.agenda.home;

import java.util.HashMap;
import java.util.Map;

import org.uqbar.commons.model.Entity;
import org.uqbar.commons.model.Home;

import ar.unq.edu.agenda.persist.DummyPersistHomeFactory;
import ar.unq.edu.agenda.persist.HomeFactory;


/**
 * Modelo de aplicacion que representa 
 */
public class Agenda {
	private static Map<Class<?>, Home<?>> homes;

	@SuppressWarnings("unchecked")
	public static synchronized <T extends Entity> Home<T> getHome(Class<T> type) {
		if (homes == null) {
			initialize();
		}
		return (Home<T>) homes.get(type);
	}

	public static void initialize(HomeFactory factory) {
		//HARDCODED: coupled with in-memory homes. 
		Map<Class<?>, Home<?>> homes = new HashMap<Class<?>, Home<?>>();
		factory.addHomes(homes);
		Agenda.homes = homes;
	}
	
	public static synchronized void initialize() {
		initialize(new DummyPersistHomeFactory()); 
	}


}